home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / dev / gui / BGUI11c.lha / demos / Addbuttons.c < prev    next >
C/C++ Source or Header  |  1994-09-07  |  6KB  |  182 lines

  1. /*
  2. **         $RCSfile: Addbuttons.c,v $
  3. **      Description: Simple demonstration how to add and insert
  4. **                   objects.
  5. **        Copyright: (C) Copyright 1994 Paul Weterings
  6. **                   All Rights Reserved.
  7. **
  8. **          $Author: Paul $
  9. **        $Revision: 1.2 $
  10. **            $Date: 1994/09/07 6:43:03 $
  11. **/
  12.  
  13. #include <libraries/bgui.h>
  14. #include <libraries/bgui_macros.h>
  15. #include <libraries/gadtools.h>
  16. #include <clib/alib_protos.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/bgui_protos.h>
  19. #include <clib/intuition_protos.h>
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23.  
  24. /*
  25. **      Library base pointer.
  26. **      NOTE: The intuition.library is opened by DICE
  27. **      it's auto-init code.
  28. **/
  29. struct Library                  *BGUIBase;
  30.  
  31. /*
  32. **      Object ID's. Please note that the ID's are shared
  33. **      between the menus and the gadget objects.
  34. **/
  35. #define ID_ADD                21
  36. #define ID_QUIT               22
  37. #define ID_INS                23
  38. #define ID_REM                24
  39.  
  40. /*
  41. **      Simple menu strip.
  42. **/
  43. struct NewMenu SimpleMenu[] = {
  44.    NM_TITLE,       "Project",      NULL,   0,      0,      NULL,
  45.    NM_ITEM,        "Add",          "a",    0,      0,      ( APTR )ID_ADD,
  46.    NM_ITEM,        "Insert",       "i",    0,      0,      ( APTR )ID_INS,
  47.    NM_ITEM,        "Remove all",   "r",    0,      0,      ( APTR )ID_REM,
  48.    NM_ITEM,        NM_BARLABEL,    NULL,   0,      0,      NULL,
  49.    NM_ITEM,        "Quit",         "Q",    0,      0,      ( APTR )ID_QUIT,
  50.    NM_END,         NULL,           NULL,   0,      0,      NULL
  51. }
  52. ;
  53.  
  54. int main( int argc, char *argv[] )
  55. {
  56.    struct Window           *window;
  57.    Object                  *WO_Window, *GO_Add, *GO_Quit, *GO_Ins, *GO_Rem, *addobj[20], *base;
  58.    ULONG                    signal = 0, rc, tmp = 0;
  59.    BOOL                     running = TRUE, ok = FALSE;
  60.    int                      x = 0, xx;
  61.  
  62.    if ( BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION ))
  63.    {
  64.  
  65.       WO_Window = WindowObject,
  66.       WINDOW_Title,           "Add/Insert Demo",
  67.       WINDOW_MenuStrip,       SimpleMenu,
  68.       WINDOW_SizeGadget,      TRUE,
  69.       WINDOW_MasterGroup,
  70.          base = HGroupObject,
  71.             StartMember, GO_Add  = XenKeyButton( "_Add", ID_ADD ), EndMember,
  72.             StartMember, GO_Ins  = XenKeyButton( "_Insert", ID_INS ), EndMember,
  73.             StartMember, GO_Rem  = XenKeyButton( "_Remove all", ID_REM ), EndMember,
  74.             StartMember, GO_Quit = XenKeyButton( "_Quit",  ID_QUIT  ), EndMember,
  75.          EndObject,
  76.       EndObject;
  77.  
  78.       if ( WO_Window )
  79.       {
  80.          tmp += GadgetKey( WO_Window, GO_Add, "a" );
  81.          tmp += GadgetKey( WO_Window, GO_Quit,  "q" );
  82.          tmp += GadgetKey( WO_Window, GO_Ins,  "i" );
  83.          tmp += GadgetKey( WO_Window, GO_Rem,  "r" );
  84.  
  85.          if ( tmp == 4 )
  86.          {
  87.             if ( window = WindowOpen( WO_Window ))
  88.             {
  89.                GetAttr( WINDOW_SigMask, WO_Window, &signal );
  90.                do
  91.                {
  92.                   Wait( signal );
  93.                   while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE )
  94.                   {
  95.                      switch ( rc )
  96.                      {
  97.                         case  WMHI_CLOSEWINDOW:
  98.                         case  ID_QUIT:
  99.                            running = FALSE;
  100.                            break;
  101.                         case  ID_ADD:
  102.                            x++;
  103.                            WindowClose( WO_Window );
  104.  
  105.                            addobj[x]  = KeyButton( "Added",  x  );
  106.  
  107.                            ok = DoMethod( base, GRM_ADDMEMBER, addobj[x],
  108.                                                 LGO_FixMinHeight, FALSE,
  109.                                                 LGO_Weight,       DEFAULT_WEIGHT,
  110.                                                 TAG_END );
  111.  
  112.                            window = WindowOpen( WO_Window );
  113.                            if (!window)
  114.                            goto error;
  115.                            break;
  116.                         case  ID_REM:
  117.                            if (x>0)
  118.                            {
  119.                               WindowClose( WO_Window );
  120.  
  121.                               for (xx=1;xx<=x;xx++)
  122.                                  DoMethod( base, GRM_REMMEMBER, addobj[xx]);
  123.  
  124.                               window = WindowOpen( WO_Window );
  125.                               x=0;
  126.                            }
  127.                            else
  128.                               printf("Were out of gadgets!\n");
  129.  
  130.                            break;
  131.                         case  ID_INS:
  132.                            x++;
  133.                            WindowClose( WO_Window );
  134.  
  135.                            addobj[x]  = KeyButton( "Inserted",  x  );
  136.  
  137.                            ok = DoMethod( base, GRM_INSERTMEMBER, addobj[x], GO_Rem,
  138.                                                 LGO_FixMinHeight, FALSE,
  139.                                                 LGO_Weight,       DEFAULT_WEIGHT,
  140.                                                 TAG_END );
  141.                            window = WindowOpen( WO_Window );
  142.                            if (!window)
  143.                            goto error;
  144.                            break;
  145.  
  146.                      }
  147.                   }
  148.                }
  149.                while ( running );
  150.             }
  151.             else
  152.                puts ( "Could not open the window" );
  153.          }
  154.          else
  155.             puts( "Could not assign gadget keys" );
  156. error:
  157.          DisposeObject( WO_Window );
  158.       }
  159.       else
  160.           puts( "Could not create the window object" );
  161.       CloseLibrary( BGUIBase );
  162.    }
  163.    else
  164.       puts( "Unable to open the bgui.library" );
  165.  
  166.    return( 0 );
  167. }
  168.  
  169. #ifdef _DCC
  170. int wbmain( struct WBStartup *wbs )
  171. {
  172.    return( main( 0, NULL ));
  173. }
  174. #endif
  175.  
  176. /*
  177.  *      $Log: Addbuttons.c,v $
  178.  * Revision 1.2  1994/09/07  6:43:03  Paul
  179.  * Initial revision
  180.  *
  181.  */
  182.